Skip to content

Conversation

@ewesterhoff
Copy link

No description provided.

@@ -0,0 +1,190 @@
"""TODO: Put your header comment here."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:P

if min_depth < 1:
var = random.randint(1,2)
if var == 1:
return lambda x,y: x

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your implementations of lambda functions are correct/functional, but you aren't quite realizing some of the benefits of lambda-izing - for example, lambda-izing functions allows you to choose/pass around functions instead of specifically checking things like rand_int values.

That being said, I do quite like how you've used them to make build_random_function also build the evaluation path - that's quite elegant, in my opinion! All in all, solidly done.

inner = build_random_function(min_depth, max_depth)
return lambda x,y: math.sin(30 * math.pi * inner(x,y))

print('error')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out https://docs.python.org/3/tutorial/errors.html#raising-exceptions - you can also raise errors, rather than printing and then returning nothing. Essentially, you can make a custom error if you want that degree of control over the program.

(Though, unless the built-in random library broke, this error should never appear - rand_int should always give you one of those values, so you should be fine either way.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants